using Game.Config;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;

namespace Game.Core
{
    public partial class SpawnSystem
    {
        protected void SpawnCapsule(float3 position)
        {
            if (ECSPrefab.PrefabMap.TryGetValue("Capsule", out var prefab))
            {
                Entity entity = EntityManager.Instantiate(prefab);
                // DynamicBuffer<StaticProperty> buffer = EntityManager.AddBuffer<StaticProperty>(entity);
                // buffer.Add(new StaticProperty()
                // {
                //     Source = PropertySource.Character,
                //     Value = 1,
                // });
                // EntityManager.AddBuffer<BaseProperty>(entity);
                // EntityManager.AddBuffer<DynamicProperty>(entity);
                
                if (EntityManager.AddComponent<PropertyData>(entity))
                {
                    EntityManager.SetComponentData(entity, new PropertyData()
                    {
                        // Static = new Property()
                        // {
                        //     Source = PropertySource.Character,
                        //     Type = PropertyType.Default,
                        //     Value = 1,
                        // },
                        Refresh = PropertyRefresh.Init,
                        Base = PropertyUtil.CalcPropertyData(1),
                    });
                }
                
                EntityManager.AddBuffer<PropertyModifier>(entity);

                
                
                EntityManager.AddComponent<Attackable>(entity);
                EntityManager.AddComponent<Damageable>(entity);
                EntityManager.AddComponent<Movable>(entity);

                EntityManager.SetComponentData<LocalTransform>(entity, new LocalTransform()
                {
                    Position = position
                });
            }
        }
    }
}